package com.demo.petshop.controller;

import com.demo.petshop.entity.Users;
import com.demo.petshop.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class UsersController {

    @Autowired
    private UsersService usersService;

    @PostMapping("login")
    public Object login(@RequestBody Users users){
        return usersService.login(users);
    }

    @PostMapping("register")
    public Object register(@RequestBody Users user){
        return usersService.register(user);
    }
    
    @GetMapping("checkLogin")
    public Object checkLogin() {
        return usersService.checkLog();
    }
    
    @GetMapping("profile")
    public Object getUserProfile() {
        return usersService.getUserProfile();
    }
    
    @PostMapping("updateprofile")
    public Object updateUserProfile(@RequestBody Map<String, Object> userData) {
        return usersService.updateUserProfile(userData);
    }
    
    @PostMapping("password")
    public Object updatePassword(@RequestBody Map<String, Object> passwordData) {
        return usersService.updatePassword(passwordData);
    }
    
    @PostMapping("settings")
    public Object updateUserSettings(@RequestBody Map<String, Object> settingsData) {
        return usersService.updateUserSettings(settingsData);
    }
    
    @PostMapping("clear-cache")
    public Object clearUserCache() {
        return usersService.clearUserCache();
    }
    
    @PostMapping("logout")
    public Object logout() {
        // 实际的登出逻辑可能涉及清除会话或令牌，这里简单返回成功
        return usersService.checkLog();
    }
}
